/**
 * A symbol object used for storing symbol
 * information on the symbol table.
 * 
 * @author James Stanier
 */
public class Symbol implements Comparable {
	String type;
	int id;
	String label;
	int lineNumber;
	
	/**
	 * Constructor.
	 * @param s The lexeme representing the symbol.
	 * @param i The id number of the symbol.
	 * @param t The type of the symbol.
	 * @param l The line number that the symbol starts on.
	 */
	public Symbol(String s, int i, String t, int l) {
		label = s;
		id = i;
		type = t;
		lineNumber = l;
	}
	
	/**
	 * Set the type of the symbol.
	 * @param s The type to be set to.
	 */
	public void setType(String s) {
		type = s;
	}
	
	/**
	 * Get the type of the symbol.
	 * @return The symbol's type.
	 */
	public String getType() {
		return type;
	}
	
	/**
	 * Set the id number of the symbol.
	 * @param i The new id number.
	 */
	public void setID(int i) {
		id = i;
	}
	
	/**
	 * Get the id number of the symbol.
	 * @return The symbol's id number.
	 */
	public int getID() {
		return id;
	}
	
	/**
	 * Set the label of the symbol manually.
	 * @param s The new label.
	 */
	public void setLabel(String s) {
		label = s;
	}
	
	/**
	 * Get the label of the symbol.
	 * @return The symbol's label.
	 */
	public String getLabel() {
		return label;
	}
	
	/**
	 * Get the line number that the symbol starts on.
	 * @return The symbol's line number.
	 */
	public int getLineNumber() {
		return lineNumber;
	}
	
	/**
	 * Comparison method to compare symbols lexicographically.
	 */
	public int compareTo(Object s) throws ClassCastException {
		if(s instanceof Symbol) {
			String a = this.getLabel().toLowerCase();
			String b = ((Symbol)s).getLabel().toLowerCase();
			return a.compareTo(b);
		}
		else {
			throw new ClassCastException("Object is not of type Symbol.");
		}
	}
}
